package languageacquisition;

import java.text.DecimalFormat;

public class Correlation {
	private double value = 0.0;
	private long top = 0;
	private long corrections = 0;
	
	public Correlation(){};
	
	public Correlation(double value) {
		this.value = value;
	}
	
	public void increase() {
		++corrections;
		++top;
		update();
	}
	
	public void decrease() {
		++corrections;
		if (top > 0) --top;
		update();
	}
	
	public double getValue() {
		return value;
	}

	public long getCorrections() {
		return corrections;
	}

	private void update() {
		value = (double) top / corrections;
	}
	
	public String toString() {
		DecimalFormat df = new DecimalFormat("0.000");
		return df.format(value) + " (" + Long.toString(corrections) + ")";
	}
	
	public boolean isStatic() {
		return corrections == 0L;
	}

}
